package com.hnqcgc.controller;

import com.hnqcgc.service.ICompanyService;
import com.hnqcgc.service.impl.CompanyServicelmpl;
import com.hnqcgc.vo.TCompany;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

@WebServlet("/CompanyServlet")
public class CompanyServlet extends BaseServlet{
    ICompanyService coms=new CompanyServicelmpl();
    @Override
    public String home(HttpServletRequest request, HttpServletResponse response) {
        String pageNow=request.getParameter("pageNow");
        int pagenum=1;
        if (!"".equals(pageNow)&&pageNow!=null){
            pagenum=Integer.parseInt(pageNow);
        }
        List<TCompany> all=coms.queryAll();
        List<TCompany> list=coms.queryByPage(10,pagenum);
        list.forEach(s->System.out.println(s.toString()));

        int totals=all.size();
        request.getSession().setAttribute("totals",totals);

        int pages=totals%10==0?totals/10:totals/10+1;
        request.getSession().setAttribute("pages",pages);
        request.getSession().setAttribute("pageNow",pagenum);
        request.getSession().setAttribute("companies",list);
        return "f:BasicInformation";
    }
}
